﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using SubsDownloader;
using SubsDownloader.Processing;
using SubsDownloader.Websites.Addic7ed;
using Episode = SubsDownloader.Websites.Addic7ed.Episode;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0 || string.IsNullOrEmpty(args[0]))
                {
                    QueueProcessor.HandleQueue();
                }
                else
                {
                    FileAttributes fileAttr;
                    try
                    {
                        fileAttr = File.GetAttributes(args[0]);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("The provided path was not found.");
                        return;
                    }
                    if (fileAttr.HasFlag(FileAttributes.Directory))
                    {
                        var folderProcessor = new FolderProcessor(args[0], true);
                        if (folderProcessor.ValidFolder)
                            folderProcessor.DownloadSubtitles(true);
                    }
                    else
                    {
                        var fileProcessor = new FileProcessor(args[0], args.Length == 6 ? args[1] : null);
                        if (fileProcessor.ValidFile)
                            fileProcessor.DownloadSubtitles(true);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine("An error occurred: {0}", e);
            }
        }
    }
}
